package com.pucong.gitee.database.backup.business.database.controller;

import com.pucong.gitee.database.backup.business.database.service.OperationDataSqlService;
import com.pucong.gitee.database.backup.common.entity.database.dto.AutoDataSourceKeywordsDto;
import com.pucong.gitee.database.backup.common.entity.database.dto.SelectDbBackTreeDto;
import com.pucong.gitee.database.backup.common.entity.database.vo.DbBackTreeVo;
import com.pucong.gitee.database.backup.common.entity.database.vo.DbTableFiledVo;
import com.pucong.gitee.database.backup.utils.Res;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author pucong
 * @url https://gitee.com/pucong
 * @create 2020-06-23
 */
@RestController
@RequestMapping("/operation/dataSql")
@Api(value = "sql操作-API ", tags = "6. sql操作 API")
public class OperationDataSqlController {

    @Autowired
    private OperationDataSqlService operationDataSqlService;

    @GetMapping("/getDataSourceTreeList")
    @ApiOperation(value = "根据上级 查询下级数据源数据")
    public Res<List<DbBackTreeVo>> getDataSourceTreeList(SelectDbBackTreeDto dto) {
        List<DbBackTreeVo> databaseTreeList = operationDataSqlService.getDataSourceTreeList(dto);
        return Res.ok(databaseTreeList);
    }

    @GetMapping("/getTableFiledListByDBInfo")
    @ApiOperation(value = "获取该数据源下的表名和字段名称 关键词显示用")
    public Res<List<DbTableFiledVo>> getTableFiledListByDBInfo(AutoDataSourceKeywordsDto dto) {
        List<DbTableFiledVo> dbTableFiledVos = operationDataSqlService.getTableFiledListByDBInfo(dto);
        return Res.ok(dbTableFiledVos);
    }
}
